home *** CD-ROM | disk | FTP | other *** search
/ bioinformatics.org / bioinformatics.org_software.tar / www.bioinformatics.org / download / ecell2 / ecell220setup.exe / {app} / standard / SRCJ / Tracer.java < prev    next >
Text File  |  2002-05-22  |  47KB  |  1,681 lines

  1.  
  2. /**
  3.  * title:     Tracer class (Tracer.java)<p>
  4.  * description  : Tracer window class<p>
  5.  * Copyright (C) 1996-2001 Keio University <p>
  6.  * Copyright (C) 1998-2001 Japan Science and Technology Corporation (JST)<p>
  7.  *               GNU General Public Licence <p>
  8.  * Division:     Mitui Knowledge Industry Co. Ltd. Bioscience division <p>
  9.  * Version :     $Id: Tracer.java,v 1.8 2002/05/13 00:23:04 ota Exp $ <p>
  10. */
  11.  
  12. package ecell;
  13.  
  14.  
  15. import java.awt.*;
  16. import java.awt.event.*;
  17. import javax.swing.border.*;
  18. import javax.swing.*;
  19. import javax.swing.plaf.basic.*;
  20. import java.util.Vector;
  21. import java.awt.geom.*;
  22. // 2001.7.26 akira shiozawa
  23. import ecell.TracerDataManager;
  24.  
  25. /**
  26.  * Class for displaying Tracer window and Drawing Graphics
  27.  * @author      XD.Zheng
  28.  * @version     1.0
  29.  * @since       JDK1.2.2
  30.  */
  31.  
  32. /*
  33. public class Tracer extends JFrame  implements ActionListener,AccessListener{
  34. */
  35. public class Tracer extends ECell2Interface
  36. {
  37.  
  38.     JPanel jp1 = new JPanel();
  39.     JPanel jp2 = new JPanel();
  40.     JPanel jp3 = new JPanel();
  41.     GPanel grap = new GPanel(this);
  42.     JPanel jp22 = new JPanel();
  43.     JLabel label1 = new JLabel("    :    ");
  44.     JLabel label2 = new JLabel("    :    ");
  45.     JPanel jp31 = new JPanel();
  46.     JPanel jp32 = new JPanel();
  47.     JButton buttonClose = new JButton("Close");
  48.     JButton buttonAdd = new JButton("Add");
  49.     JButton buttonSave = new JButton("Save");
  50.  
  51.     JCheckBox[] jCheckBox =new JCheckBox[8];
  52.     JRadioButton radioQuantity = new JRadioButton("quantity");
  53.     JRadioButton radioConcent = new JRadioButton("concentration");
  54.  
  55.     /**
  56.      * X-coordinate beginning to clip the rectangle region
  57.      */
  58.     int xBegin=30;
  59.  
  60.     /**
  61.      * X-coordinate end to clip the rectangle region 
  62.      */
  63.     int xEnd=630;
  64.  
  65.     /*
  66.      * Y-coordinate beginning to clip the rectangle region 
  67.      */
  68.     int yBegin=320;
  69.  
  70.     /**
  71.      * Y-coordinate end to clip the rectangle region 
  72.      */
  73.     int yEnd=20;
  74.  
  75.     /*
  76.      * Color Of Tracer Graphics
  77.      */
  78.     Color[] gColor ={Color.blue,Color.magenta,Color.orange, Color.cyan,Color.red,Color.black,new Color(124,25,182),new Color(140,17,17)};
  79.  
  80.     /**
  81.      * Substance number
  82.      */
  83.     int[] type ={-1,-1,-1,-1,-1,-1,-1,-1} ;
  84.  
  85.     /*
  86.      * Type of SubstanceWindow
  87.      */
  88.     int[] wType ={1,1,1,1,1,1,1,1};
  89.  
  90.     /**
  91.      * ClassName of Reactor
  92.      */
  93.     String[] cName=new String[8];
  94.  
  95.     /**
  96.      * Flag for start
  97.      */
  98.     int[] first= new int[8];
  99.  
  100.     /**
  101.      * Flag for magnification of the first spot
  102.      */
  103.     int mfirst=0;
  104.  
  105.     /**
  106.      * Number of Displayed Substances
  107.      */
  108.     int arraySize = 0;
  109.  
  110.     /**
  111.      * Number of current step
  112.      */
  113.     int count =-1;
  114.  
  115.     /**
  116.      * Number of previous step
  117.      */
  118.     int oldcount =-1;
  119.  
  120.     /**
  121.      * Instance of DataField
  122.      */
  123.     DataField df;
  124.  
  125.     /**
  126.      * CtrollorPanel
  127.      */
  128.     //MainWindow window;
  129.  
  130.     /**
  131.      * Tracer window number 
  132.      */
  133.     int tracerNumber =0;
  134.  
  135.  
  136.     /*
  137.      * Flag for maginification 0 Normal 1 Magnify
  138.      */
  139.     int magFlag = 0;
  140.  
  141.     /*
  142.      * Flag for minus 
  143.      */
  144.     int  minusFlag=0;
  145.  
  146.     /**
  147.      * Flag for minus when magnified 
  148.      */
  149.     int mMinusFlag=0;
  150.  
  151.     /**
  152.      * Correct value for minus
  153.      */
  154.     double correct=0.0;
  155.  
  156.     /**
  157.      * Correct value for minus when maginified
  158.      */
  159.     double mCorrect=0.0;
  160.  
  161.     /**
  162.      * Maximum time
  163.      */
  164.     double xTimeMax =0.0;
  165.  
  166.     /**
  167.      * Minimum time
  168.      */
  169.     double xTimeMin =0.0;
  170.  
  171.     /**
  172.      * Maximum data
  173.      */
  174.     double yValueMax =0.0;
  175.  
  176.     /**
  177.      * Minimum data
  178.      */
  179.     double yValueMin =0.0;
  180.  
  181.     /**
  182.      * Maximum data of each substance
  183.      */
  184.     //double[] yValueMaxs ={0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
  185.     double[][] yValueMaxs =new double[2][8];
  186.  
  187.     /**
  188.      * Minimum data of each substance
  189.      */
  190. //    double[] yValueMins ={0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
  191.     double[][] yValueMins = new double[2][8];
  192.  
  193.     /**
  194.      * Maximum time of each substance
  195.      */
  196.     double[] xTimeMaxs = new double[8];
  197. //    double[][] xTimeMaxs = {{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0},{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}};
  198.  
  199.     /**
  200.      * Minimum time of each substance
  201.      */
  202.     double[] xTimeMins = {-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0};
  203. //    double[][] xTimeMins = {{-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0},{-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0,-1.0}};
  204.  
  205.     /**
  206.      * Coordinate change rate of time
  207.      */
  208.     double xChange=600;
  209.  
  210.     /**
  211.      * Coordinate change rate of data
  212.      */
  213.     double yChange=300;
  214.  
  215.     /**
  216.      * Peak of X-coordinate
  217.      */
  218.     double xPlot =1.0;
  219.  
  220.     /**
  221.      * Peak of Y-coordinate
  222.      */
  223.     double yPlot =1.0;
  224.  
  225.     /**
  226.      * Width of X-axis
  227.      */
  228.     int iWidth = 600;
  229.  
  230.     /**
  231.      * Height of Y-axis
  232.      */
  233.     int iHigh  = 300;
  234.  
  235.     /**
  236.      * Time value of a time
  237.      */
  238.     double[]  xTime = new double[8];
  239.  
  240.     /**
  241.      * Data value at a step 
  242.      */
  243.     double[][]  yValue = new double[2][8];
  244. //    double[]  yValue = new double[8];
  245.  
  246.     /**
  247.      * Time value at the previous step
  248.      */
  249.     double[] oldXTime = new double[8];
  250.  
  251.     /**
  252.      * Data value at the previous step
  253.      */
  254. //    double[] oldYValue = new double[8];
  255.     double[][] oldYValue = new double[2][8];
  256.  
  257.     /**
  258.      * 
  259.  
  260.      */
  261. //    Vector[]   vTime = new Vector[8];
  262.  
  263.     /**
  264.      * All data values
  265.      */
  266. //    Vector[]   vValue = new Vector[8];
  267.  
  268.     /**
  269.      * X-coordinate at the first point
  270.      */
  271.     int mx0 = 0;
  272.  
  273.     /**
  274.      * Y-coordinate at the first point
  275.      */
  276.     int my0 = 0;
  277.  
  278.     /**
  279.      * X-coordinate at the second point
  280.      */
  281.     int mx1 = 0;
  282.  
  283.     /**
  284.      * Y-coordinate at the second point
  285.      */
  286.     int my1 = 0;
  287.  
  288.     /**
  289.      * Rate on magnification in the X-axis 
  290.      */
  291.     double mxChange=600;
  292.  
  293.     /**
  294.      * Rate on magnification in the Y-axis 
  295.      */
  296.     double myChange=300;
  297.  
  298.     /**
  299.      * Initial value for the range of magnification along the time 
  300.      */
  301.     double mxTimeBegin =0.0;
  302.  
  303.     /**
  304.      * Final value for the range of magnification along the time 
  305.      */
  306.     double mxTimeEnd   =0.0;
  307.  
  308.     /**
  309.      * Final value for the range of magnification for the data 
  310.      */
  311.     double myValueBegin =0.0;
  312.  
  313.     /**
  314.      * Final value for the range of magnification for the data 
  315.      */
  316.     double myValueEnd   =0.0;
  317.  
  318.     /**
  319.      * Range of the magnified state in the X-axis 
  320.      */
  321.     double mxPlot =0.0;
  322.  
  323.     /**
  324.      * Range of the magnified state in the Y-axis 
  325.      */
  326.     double myPlot =0.0;
  327.  
  328.     /**
  329.      * coordinates of four vertrices to specify the range for maginification 
  330.      */
  331.     int  rx0;
  332.     int  ry0;
  333.     int  rx1;
  334.     int  ry1;
  335.  
  336.     /**
  337.      * Cursor x 
  338.      */
  339.     public static double mousex =0;
  340.  
  341.     /**
  342.      * Cursor y 
  343.      */
  344.     public static double mousey =0;
  345.  
  346.     /**
  347.      * Flag for dragging with mouse 
  348.      */
  349.     boolean rflag =false;
  350.  
  351.     /**
  352.      * 2001.7.26 akira shiozawa
  353.      */
  354.     TracerDataManager dman = new TracerDataManager();
  355.  
  356.     /**
  357.      * 2002.1.23 flag for quantity(0)/concentration(1) mode
  358.      */
  359.     protected int nTracerFlag = 0;
  360.     
  361.     
  362.     
  363.     /**
  364.      * Constructor 
  365.      * @param  window     Control Panel
  366.      */
  367.     public Tracer(MainWindow window) {
  368.  
  369.         // 2002.4. akira shiozawa
  370.         super( window );
  371.  
  372.         jbInit();
  373.  
  374.     }
  375.  
  376.     /**
  377.      * Constructor 
  378.      * @param window     Control Panel
  379.      * @param number     Number of the window, called by the control panel 
  380.      */
  381.     public Tracer(MainWindow window,int number){
  382.  
  383.         // 2002.4. akira shiozawa
  384.         super( window );
  385.  
  386.         tracerNumber = number;
  387.         try {
  388.             //this.window = window;
  389.             jbInit();
  390.             window.addAccessListener( this );
  391.  
  392.         }
  393.         catch(Exception e) {
  394.             window.messageWindow.setErrorMessage( e );
  395.         }
  396.     }
  397.  
  398.  
  399.     /**
  400.      * Initialization
  401.      * @return void
  402.      */
  403.     public void jbInit()/* throws Exception */{
  404.         this.setResizable(true);
  405.         this.getContentPane().setBackground(Color.lightGray);
  406.         //this.setSize(new Dimension(670, 470));
  407.         this.setSizeAndLocation(new Dimension(670, 470), new Point(150, 100));
  408.         this.setTitle("Tracer");
  409.  
  410.         buttonClose.addActionListener(this);
  411.         buttonAdd.addActionListener(this);
  412.         buttonSave.addActionListener(this);
  413.         jp1.setLayout(new FlowLayout(0,2,0));
  414.         jp1.setPreferredSize(new Dimension(500,51));
  415.         jp31.setLayout(new FlowLayout(0,0,0));
  416.  
  417.         jp31.add(buttonClose);
  418.         jp31.add(buttonAdd);
  419.         jp31.add(buttonSave);
  420.  
  421.         
  422.         for(int i=0;i<8;i++){
  423.             // 2001.6.28 comment out by akira shiozawa
  424.             /*
  425.             vTime[i] = new Vector();
  426.             vValue[i] = new Vector();
  427.             */
  428.             jCheckBox[i]=new JCheckBox();
  429.             jCheckBox[i].addMouseListener( myMouseAdapter);
  430.             jCheckBox[i].addActionListener(this);
  431.             jCheckBox[i].setVisible(false);
  432.             jCheckBox[i].setForeground(gColor[i]);
  433.         }
  434.  
  435.         grap.setBackground(Color.white);
  436.         grap.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(Color.white,new Color(178, 178, 178)),BorderFactory.createEmptyBorder(5,5,5,5)));
  437.         grap.addMouseListener(new MouseAdapter() {
  438.             public void mousePressed(MouseEvent e) {
  439.                 if (e.getModifiers() == e.BUTTON1_MASK){
  440.                     int pointx = e.getX();
  441.                     int pointy = e.getY();
  442.  
  443.                     Tracer.mousex = 0.0;
  444.                     Tracer.mousey = 0.0;
  445.  
  446.                     pointx = pointx - xBegin;
  447.                     pointy = yBegin - pointy;
  448.                     
  449.                     if(magFlag==0){
  450.                         double dx = pointx/xChange;
  451.                         double dy=  pointy/yChange;
  452.                         if(dx>=0 && dy>=0 && pointx <= iWidth && pointy <= iHigh){
  453.                             double my=dy-correct;
  454.                             //label1.setText(""+ getDoubleValue(dx) +":" + getDoubleValue(my));
  455.                             Tracer.mousex = dx;
  456.                             Tracer.mousey = /*dy*/my;
  457.                         }
  458. /**
  459.                         else{
  460.                             //label1.setText("    :    ");
  461.                         }
  462. **/
  463.                     }else if(magFlag==1){
  464.                         double dx = pointx/mxChange + mxTimeBegin;
  465.                         double dy = pointy/myChange+ myValueBegin;
  466.                         if(dx>=mxTimeBegin && dy>=myValueBegin && dx <= mxTimeEnd && dy <= myValueEnd){
  467.                             double my= dy-mCorrect;
  468.                             //label1.setText(""+ getDoubleValue(dx) +":" + getDoubleValue(my));
  469.                             Tracer.mousex = dx;
  470.                             Tracer.mousey = /*dy*/my;
  471.                         }
  472. /**
  473.                         else{
  474.                             //label1.setText("    :    ");
  475.                         }
  476. **/
  477.                     }
  478.                     // 2002.5
  479.                     //grap.repaint();
  480.                     window.repaintAllTracers();
  481.                 }else if(e.getModifiers() == e.BUTTON3_MASK){
  482.                     if(e.getClickCount()==1){
  483.                         rx0 = e.getX();
  484.                         ry0 = e.getY();
  485.                         if(rx0<xBegin)
  486.                             rx0=xBegin;
  487.                         if(rx0>(xBegin +iWidth))
  488.                             rx0=xBegin+iWidth;
  489.                         if(ry0>yBegin)
  490.                             ry0 = yBegin;
  491.                         if(ry0<(yBegin-iHigh))
  492.                             ry0= yBegin -iHigh;
  493.                     }else if(e.getClickCount()==2){
  494.                         magFlag=0;
  495.                         grap.repaint();
  496.                     }
  497.                 }
  498.  
  499.             }
  500.  
  501.  
  502.             public void mouseReleased(MouseEvent me) {
  503.                 if(me.getModifiers() == me.BUTTON3_MASK){
  504. //System.out.println( "rflag:" + rflag + "/rx0:" + rx0 + "/rx1:" + rx1 + "/ry0:" + ry0 + "/ry1:" + ry1 );
  505.                     if(rflag ==true && rx0!=rx1 && ry0!=ry1){
  506.                         rflag =false;
  507.                         if(rx1>rx0){
  508.                             mx1 =rx1;
  509.                             mx0=rx0;
  510.                         }else{
  511.                             mx1 =rx0;
  512.                             mx0=rx1;
  513.                         }
  514.                         if(ry1>ry0){
  515.                             my0 =ry1;
  516.                             my1=ry0;
  517.                         }else{
  518.                             my0 =ry0;
  519.                             my1=ry1;
  520.                         }
  521.                         magnifyTracer();
  522.                     }
  523.                     rflag=false;
  524.                     rx0=0;
  525.                     ry0=0;
  526.                     rx1=0;
  527.                     ry1=0;
  528.                     grap.repaint();
  529.                 }
  530.             }
  531.         });
  532.         grap.addMouseMotionListener(new MouseMotionAdapter() {        
  533.             public void mouseDragged(MouseEvent e){
  534.                 if(e.getModifiers() == e.BUTTON3_MASK){
  535.                     rflag=true;
  536.                     rx1 = e.getX();
  537.                     ry1 = e.getY();
  538.                     if(rx1<xBegin)
  539.                         rx1=xBegin;
  540.                     if(rx1>(xBegin +iWidth))
  541.                         rx1=xBegin+iWidth;
  542.                     if(ry1>yBegin)
  543.                         ry1 = yBegin;
  544.                     if(ry1<(yBegin-iHigh))
  545.                         ry1= yBegin -iHigh;
  546.  
  547.                     if(rx0<xBegin)
  548.                             rx0=xBegin;
  549.                         if(rx0>(xBegin +iWidth))
  550.                             rx0=xBegin+iWidth;
  551.                         if(ry0>yBegin)
  552.                             ry0 = yBegin;
  553.                         if(ry0<(yBegin-iHigh))
  554.                             ry0= yBegin -iHigh;
  555.                     grap.repaint();
  556.                 }
  557.             }
  558.  
  559.             public void mouseMoved(MouseEvent e) {
  560.                 int pointx = e.getX();
  561.                 int pointy = e.getY();
  562.                 //pointx = pointx -30;
  563.                 pointx = pointx - xBegin;
  564.                 //pointy = 320-pointy;
  565.                 pointy = yBegin - pointy;
  566.                 if(magFlag==0){
  567.                     double dx = pointx/xChange;
  568.                     double dy=  pointy/yChange;
  569.                     if(dx>=0 && dy>=0){
  570.                         double my=dy-correct;
  571.                         label2.setText(""+ getDoubleValue(dx) +":" + getDoubleValue(my));
  572.                     }else{
  573.                         label2.setText("    :    ");
  574.                     }
  575.                 }else if(magFlag==1){
  576.                     double dx = pointx/mxChange + mxTimeBegin;
  577.                     double dy = pointy/myChange+ myValueBegin;
  578.                     if(dx>=mxTimeBegin && dy>=myValueBegin){
  579.                         double my=dy-mCorrect;
  580.                         label2.setText(""+ getDoubleValue(dx) +":" + getDoubleValue(my));
  581.                     }else{
  582.                         label2.setText("    :    ");
  583.                     }
  584.                 }
  585.             }
  586.  
  587.  
  588.         });
  589.         
  590.         // 2002.3.25 akira shiozawa
  591.         this.addComponentListener( new ComponentAdapter() {
  592.             public void componentResized( ComponentEvent e )
  593.             {
  594.                 xEnd = (grap.getWidth() - grap.xMarginR);
  595.                 yBegin = (grap.getHeight() - grap.yMarginB);
  596.                 if( magFlag != 0 )
  597.                 {
  598.                     // 2002.3.25 akira shiozawa
  599.                     iWidth = xEnd - xBegin;
  600.                     iHigh = yBegin - yEnd;
  601.                     mxChange =iWidth/(mxTimeEnd-mxTimeBegin);
  602.                     if(mxChange<0) mxChange =- mxChange;
  603.                     myChange = iHigh/(myValueEnd-myValueBegin);
  604.                     if(myChange<0) myChange = - myChange;
  605.                 }
  606.             }
  607.             
  608.         });
  609.         
  610.         jp1.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(142, 142, 142)),"Tracer"));
  611.         for(int i=0; i<8;i++){
  612.             jp1.add(jCheckBox[i]);
  613.         }
  614.         jp2.setLayout(new BorderLayout());
  615.         jp2.add(grap,"Center");
  616.  
  617.         jp22.setLayout(new FlowLayout(0,30,3));
  618.         jp22.add(label1);
  619.         jp22.add(label2);
  620.         jp2.add(jp22,"South");
  621.  
  622.  
  623.         ButtonGroup buttonGroup = new ButtonGroup();
  624.         buttonGroup.add(radioQuantity);
  625.         buttonGroup.add(radioConcent);
  626.         jp32.setLayout(new FlowLayout(2,0,0));
  627.         jp32.add(radioQuantity);
  628.         jp32.add(radioConcent);
  629.         // 2002.1.23 akira shiozawa
  630.         radioQuantity.addActionListener( this );
  631.         radioConcent.addActionListener( this );
  632.         radioQuantity.setSelected( true );
  633.         
  634.         jp3.setLayout(new BorderLayout());
  635.         jp3.add(jp31,"West");
  636.         jp3.add(jp32,"East");
  637.  
  638.         this.getContentPane().add(jp1,"North");
  639.         this.getContentPane().add(jp2,"Center");
  640.         this.getContentPane().add(jp3,"South");
  641.  
  642.         // 2002.1.16
  643.         this.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
  644.         
  645.         // 2002.2.19 get current time
  646.         xTimeMax = window.df.getTime();
  647. //System.out.println( "current time:" + xTimeMax );
  648.     }
  649.  
  650.  
  651.     /**
  652.      * Access event processing
  653.      * @param win     Instance of MainWindow
  654.      * @return void
  655.      */
  656.     public void accessJni( MainWindow  win) {
  657.         // 2001.10.19 stop running when io exception has occurred
  658.         try
  659.         {
  660.             setRunningFlag( true );
  661.             if( !grap.bPainting )
  662.             {
  663.                 drawTracer();
  664.             }
  665.             setRunningFlag( false );
  666.         }
  667.         catch( java.io.IOException e )
  668.         {
  669.             window.messageWindow.setErrorMessage( e );
  670.             //Object message = e.getMessage();
  671.             String title ="E-Cell Tracer";
  672.             int type = JOptionPane.INFORMATION_MESSAGE;
  673.             JOptionPane.showMessageDialog( this, e.getMessage(), title, type );
  674.             window.stopAction();
  675.             return;
  676.         }
  677.     }
  678.  
  679.     /**
  680.      * Action event processing
  681.      * @param e       Instance of ActionEvent
  682.      * @return void
  683.      */
  684.     public void actionPerformed(ActionEvent e) {
  685.  
  686.         for(int i=0;i<arraySize;i++){
  687.             if(e.getSource()==jCheckBox[i]){
  688.  
  689.                 // 2002.1.23 akira shiozawa
  690.                 getMaxValue();
  691.                 defineScale();
  692.  
  693.                 this.repaint();
  694.                 break;
  695.             }
  696.         }
  697.  
  698.         if(e.getSource() == buttonClose){
  699.             if( confirmExit() )
  700.             {
  701.                 exit_actionPerformed();
  702.             }
  703.         }
  704.  
  705.         if(e.getSource() == buttonAdd){
  706.             if(window.selectorFlag==false){
  707.                 window.selector = new EntrySelector(0,window);
  708.                 window.selectorFlag = true;
  709.                 window.selector.setTracer(this);
  710.                 window.selector.setVisible(true);
  711.                 window.selector.setLocation(150,100);
  712.             }else{
  713.                 if(window.selector.isVisible()){
  714.                     Object message ="Entry Selector is be using by other window";
  715.                     String title ="E-Cell Tracer";
  716.                     int messageType = JOptionPane.INFORMATION_MESSAGE;
  717.                         JOptionPane.showMessageDialog(this,message,
  718.                                                                         title,messageType);
  719.                     return;
  720.                 }
  721.                 window.selector.setEntrySelector(0);
  722.                 window.selector.setTracer(this);
  723.                 window.selector.setVisible(true);
  724.  
  725.  
  726.             }
  727.             try{
  728.                 window.df.setTracerState(tracerNumber,1);
  729.             }catch(Exception ex){
  730.                 window.messageWindow.setErrorMessage( ex );
  731.             }
  732.         }
  733.  
  734.         if(e.getSource() == buttonSave){
  735.             window.df.saveTracer(tracerNumber);
  736.         }
  737.         
  738.         
  739.         // 2002.1.23 for concentration
  740.         if( e.getSource() == radioQuantity ||
  741.             e.getSource() == radioConcent )
  742.         {
  743.             int flg = (e.getSource() == radioConcent)?  1 : 0;
  744.             if( nTracerFlag != flg )
  745.             {
  746.                 nTracerFlag = flg;
  747.                 Tracer.mousex = Tracer.mousey = 0.0;
  748.                 magFlag = 0;
  749.                 getMaxValue();
  750.                 defineScale();
  751.                 this.repaint();
  752.             }
  753.         }
  754.  
  755.     }
  756.  
  757.     /**
  758.      * Set item of Tracer
  759.      * @param tracerList    Substance name displayed on the window
  760.      * @param kits          Mouse right button  The character string displayed upon drawing
  761.      * @param className     Meaningless if it is Reactor or Substance class 
  762.      * @param objCodes      Substance number
  763.      * @param objType       Substance type 
  764.      * @return void
  765.      */
  766.     public void setCheckBox(String[] tracerList,String[] kits,String[] className,int[] objCodes,int[] objType){
  767.         int size = tracerList.length;
  768.         int plus = arraySize + size;
  769.  
  770.         // 2002.1.23 akira shiozawa
  771.         double data[] = new double[7];
  772.  
  773.         if(plus <8){
  774.             for(int i= arraySize;i<plus;i++){
  775.                 jCheckBox[i].setText(tracerList[i-arraySize]);
  776.                 jCheckBox[i].setVisible(true);
  777.                 jCheckBox[i].setSelected(true);
  778.                 jCheckBox[i].setToolTipText(kits[i-arraySize]);
  779.                 type[i] =objCodes[i-arraySize];
  780.                 wType[i] = objType[i-arraySize];
  781.                 cName[i] = className[i-arraySize];
  782.             }
  783.             arraySize = plus;
  784.         }else {
  785.             buttonAdd.setEnabled(false);
  786.             for(int i= arraySize;i<8;i++){
  787.                 jCheckBox[i].setText(tracerList[i-arraySize]);
  788.                 jCheckBox[i].setVisible(true);
  789.                 jCheckBox[i].setSelected(true);
  790.                 jCheckBox[i].setToolTipText(kits[i-arraySize]);
  791.                 type[i]=objCodes[i-arraySize];
  792.                 wType[i]=objType[i-arraySize];
  793.                 cName[i] = className[i-arraySize];
  794.             }
  795.             arraySize = 8;
  796.         }
  797.         
  798.         // 2002.5
  799.         if( xTimeMax == xTimeMin )
  800.         {    
  801.             for( int i = 0; i < arraySize; i++ )
  802.             {
  803.                 window.df.getInitValues( type[i], data );
  804. //System.out.println( "e_no:" + type[i] + "/time:" + data[0] + "/data:" + data[1] + "/concent:" + data[4] );
  805.                 try
  806.                 {
  807.                     dman.appendTracerData( (tracerNumber + "-" + i + "-" + type[i]), data );
  808.                     oldXTime[i] = data[0];
  809.                     oldYValue[0][i] = data[1];
  810.                     oldYValue[1][i] = data[4];
  811.                     yValueMaxs[0][i] = data[1];
  812.                     yValueMins[0][i] = data[1];
  813.                     yValueMaxs[1][i] = data[4];
  814.                     yValueMins[1][i] = data[4];
  815.                 }
  816.                 catch( Exception e )
  817.                 {
  818.                     window.messageWindow.setErrorMessage( e );
  819.                 }
  820.             }
  821.         }
  822.     }
  823.  
  824.     /**
  825.      * Calculate the new maximum data by comparing the previous maximum data and the latest one. 
  826.      * @return void
  827.      */
  828.      private void getMaxValue(){
  829.         int flag =0;
  830.         for(int i=0;i<arraySize;i++){
  831.             if(jCheckBox[i].isSelected()){
  832.                 if(flag==0  ){
  833.                     xTimeMax=xTimeMaxs[i];
  834.                     xTimeMin=xTimeMins[i];
  835.                     yValueMax=yValueMaxs[nTracerFlag][i];
  836.                     yValueMin=yValueMins[nTracerFlag][i];
  837.                     flag=1;
  838.                 }else{
  839.                     if(xTimeMin>xTimeMins[i])
  840.                         xTimeMin=xTimeMins[i];
  841.                     if(xTimeMax<xTimeMaxs[i])
  842.                         xTimeMax=xTimeMaxs[i];
  843.                     if(yValueMin>yValueMins[nTracerFlag][i])
  844.                         yValueMin=yValueMins[nTracerFlag][i];
  845.                     if(yValueMax<yValueMaxs[nTracerFlag][i])
  846.                         yValueMax=yValueMaxs[nTracerFlag][i];
  847.                 }
  848.             }
  849.  
  850.         }
  851.         if(flag ==0){
  852.             xTimeMax =0.0;
  853.             yValueMax =0.0;
  854.             xTimeMin=0.0;
  855.             yValueMin=0.0;
  856.         }
  857.     }
  858.  
  859.     public boolean defineScale()
  860.     {
  861.         double oldXPlot=xPlot;
  862.         double oldYPlot=yPlot;
  863.         boolean ret = false;
  864.         
  865.         xPlot = ceilToPow10(xTimeMax);
  866.         if(yValueMax>=0 && yValueMin>=0){
  867.             minusFlag=0;
  868.             yPlot = ceilToPow10(yValueMax);
  869.             correct=0;
  870.         }
  871.         if(yValueMax>0 && yValueMin<0){
  872.             minusFlag=1;
  873.             if(yValueMax>=-yValueMin)
  874.                 yPlot =2* ceilToPow10(yValueMax);
  875.             else
  876.                 yPlot =2* ceilToPow10(-yValueMin);
  877.             correct=0.5*yPlot;
  878.         }
  879.  
  880.         if(yValueMax<=0 && yValueMin<0){
  881.             minusFlag=2;
  882.             yPlot = ceilToPow10(-yValueMin);
  883.             correct=yPlot;
  884.         }
  885.  
  886.         if (oldXPlot!=xPlot ||oldYPlot!=yPlot){
  887.             // 2002.3.25 comment out
  888.             //mousex=0;
  889.             //mousey=0;
  890.             //this.repaint();
  891.             ret = true;
  892.             
  893.         }
  894.         
  895.         iWidth = xEnd - xBegin;
  896.         iHigh = yBegin - yEnd;
  897.         
  898.         xChange = iWidth/xPlot;
  899.         yChange = iHigh/yPlot;
  900. //System.out.println( "xChange:" + xChange + "/yChange:" + yChange + "/xPlot:" + xPlot + "/yPlot:" + yPlot + "/xTimeMax:" + xTimeMax + "/yValueMax:" + yValueMax + "/xTimeMin:" + xTimeMin + "/yValueMin:" + yValueMin );
  901.  
  902.         return ret;
  903.     }
  904.  
  905.  
  906.     private void getTracerData( int i )
  907.     {
  908.         double[] data = new double[7];
  909.  
  910.         try
  911.         {
  912. //System.out.println( "getTracerData(no." + tracerNumber + ")" );
  913.             window.df.getTracerData(0,type[i],data);
  914.  
  915.             xTime[i]=data[0];
  916.             if(xTime[i] > 0.0)
  917.             {
  918.                 if(xTimeMins[i] < 0.0)
  919.                 {
  920.                     xTimeMins[i]=data[0];
  921.                 }
  922.                 xTimeMaxs[i]=data[0];
  923.                 yValue[0][i]=data[1];
  924.                 if(    yValueMaxs[0][i]<data[1])
  925.                 {
  926.                     yValueMaxs[0][i] = data[1];
  927.                 }
  928.                 if(yValueMins[0][i]>data[1])
  929.                 {
  930.                     yValueMins[0][i] = data[1];
  931.                 }
  932.                 // 2002.1.23 for concentration
  933.                 yValue[1][i] = data[4];
  934.                 if( yValueMaxs[1][i] < data[4] )
  935.                 {
  936.                     yValueMaxs[1][i] = data[4];
  937.                 }
  938.                 if( yValueMins[1][i] > data[4] )
  939.                 {
  940.                     yValueMins[1][i] = data[4];
  941.                 }
  942.                  dman.appendTracerData( (tracerNumber + "-" + i + "-" + type[i]), data );
  943.             }
  944.             else
  945.             {
  946. //System.out.println( "index:" + i + " time=0 quantity=" + data[1] );
  947.             }
  948.         }
  949.         catch(Exception ex)
  950.         {
  951.             window.messageWindow.setErrorMessage( ex );
  952.         }
  953.     }
  954.  
  955.     /**
  956.      * Draw Graphics
  957.      * @return void
  958.      */
  959.     private void drawTracer() throws java.io.IOException
  960.     {
  961.         Graphics g = grap.getGraphics();
  962.         count++;
  963.         //double[] data;
  964.         for(int i=0;i<arraySize;i++)
  965.         {
  966.             getTracerData( i );
  967.         }
  968.  
  969.         getMaxValue();
  970.  
  971.         if( defineScale() )
  972.         {
  973.             this.repaint();
  974.         }
  975. //System.out.println( "oldXTime[1-8]:" + oldXTime[0] + "," + oldXTime[1] + "," + oldXTime[2] + "," + oldXTime[3] + "," + oldXTime[4] + "," + oldXTime[5] + "," + oldXTime[6] + "," + oldXTime[7] );
  976.         int y1=0;
  977.         int y0=0;
  978.         for(int i=0;i<arraySize;i++){
  979.             // 2002.1.24 akira shiozawa
  980.             if( xTime[i] <= 0 )
  981.             {
  982.                 if( xTime[i] == 0 )
  983.                 {
  984.                     first[i]=1;
  985.                 }
  986.                 continue;
  987.             }
  988.             if(magFlag==0){
  989. //System.out.println( "first[i]:" + first[i] + "/selected:" + jCheckBox[i].isSelected() + "/xTime[i]:" + xTime[i] );
  990.                   if(first[i]==1 && jCheckBox[i].isSelected() ){
  991.                     /*
  992.                     if(minusFlag==1){
  993.                         y1 =(int)( (yValue[i]+0.5*yPlot)*yChange);
  994.                         y0 =(int)((yValue[i]+0.5*yPlot)*yChange);
  995.                     }else if(minusFlag==2){
  996.                         y1 =(int)( (yValue[i]+yPlot)*yChange);
  997.                         y0 =(int)((yValue[i]+yPlot)*yChange);
  998.                     }else{
  999.                         y1= (int)(yValue[i]*yChange);
  1000.                         y0 =(int)(oldYValue[i]*yChange);
  1001.                     } */
  1002. //System.out.println( "type:" + type[i] + "/oldXTime:" + oldXTime[i] );
  1003.                     y1=(int)((yValue[nTracerFlag][i]+correct)*yChange);
  1004.                     y0=(int)((oldYValue[nTracerFlag][i]+correct)*yChange);
  1005.                     int x1= (int) (xTime[i]*xChange);
  1006.                     int x0= (int)(oldXTime[i]*xChange);
  1007.  
  1008.  
  1009.                     g.setColor(gColor[i]);
  1010.                     g.drawLine(x0+ xBegin ,yBegin-y0, x1+ xBegin,yBegin-y1);
  1011.                   }
  1012.             }else{
  1013.                 if(mfirst==0) this.repaint();
  1014.                 mfirst=1;
  1015.                 if(jCheckBox[i].isSelected() && xTime[i]>=mxTimeBegin && xTime[i]<=mxTimeEnd
  1016.                     && (yValue[nTracerFlag][i]+mCorrect)>=myValueBegin && (yValue[nTracerFlag][i]+mCorrect)<=myValueEnd)
  1017.                 {
  1018.  
  1019.                     int x1=(int)((xTime[i]-mxTimeBegin)*mxChange);
  1020.                     int  x0=(int)((oldXTime[i]-mxTimeBegin)*mxChange);
  1021.                     if(x0<0) x0=0;
  1022.  
  1023.                     y1=(int)((yValue[nTracerFlag][i]+mCorrect-myValueBegin)*myChange);
  1024.                     y0=(int)((oldYValue[nTracerFlag][i]+mCorrect-myValueBegin)*myChange);
  1025.                     if(y0<0) y0=0;
  1026.                     g.setColor(gColor[i]);
  1027.                     int dy0=yBegin-y0;
  1028.                     int dy1=yBegin-y1;
  1029.                     if(dy0>yBegin) dy0=yBegin;
  1030.                     if(dy0<yEnd) dy0=yEnd;
  1031.                     if(dy1>yBegin) dy1=yBegin;
  1032.                     if(dy1<yEnd) dy1=yEnd;
  1033.                     g.drawLine(x0+ xBegin ,dy0, x1+ xBegin,dy1);
  1034.                 }
  1035.             }
  1036.             first[i]=1;
  1037.             oldXTime[i]=xTime[i];
  1038.             oldYValue[0][i]=yValue[0][i];
  1039.             oldYValue[1][i]=yValue[1][i];
  1040.         }
  1041.     }
  1042.  
  1043.     /**
  1044.      * Convert Double value to suitable String.
  1045.      * @param vaule     Double data
  1046.      * @return    Converted String
  1047.      */
  1048.     public String getDoubleValue(double value){
  1049.         int dotIndex=-1;
  1050.         int eIndex=-1;
  1051.  
  1052.         String str=String.valueOf(value);
  1053.         int len=str.length();
  1054.         if(len<=8) return str;
  1055.  
  1056.  
  1057.         dotIndex=str.indexOf(".");
  1058.         eIndex=str.indexOf("E");
  1059.         if(eIndex==-1){
  1060.             if(dotIndex==-1){
  1061.                 return str;
  1062.             }else if(dotIndex==7){
  1063.                 return str.substring(0,9);
  1064.             }else if(dotIndex<7){
  1065.                 return str.substring(0,8);
  1066.             }else if(dotIndex>7){
  1067.                 return str.substring(0,dotIndex);
  1068.             }
  1069.         }else if(eIndex<=7){
  1070.             return str;
  1071.         }else{
  1072.             return (str.substring(0,7)+str.substring(eIndex,len)); 
  1073.         }
  1074.         return "";
  1075.  
  1076.     }
  1077.  
  1078.     /**
  1079.      *Magnify
  1080.      *@return void
  1081.      */
  1082.     private void magnifyTracer(){
  1083. //System.out.println( "magnifyTracer/magFlag:" + magFlag );
  1084.         int beforeFlag =0;
  1085.         double dxBegin=0.0;
  1086.         double  dxEnd=0.0;
  1087.         double dyBegin = 0.0;
  1088.         double dyEnd =0.0;
  1089.         int  ixBegin;
  1090.         int  ixEnd;
  1091.         int iyBegin;
  1092.         int iyEnd;
  1093.  
  1094.         mfirst=0;
  1095.         // 2002.3.25 comment out 
  1096.         //mousex=0;
  1097.         //mousey=0;
  1098.         
  1099.         if(magFlag ==0){
  1100.             beforeFlag=0;
  1101.             magFlag =1;
  1102.         }else{
  1103.             beforeFlag=1;
  1104.         }
  1105.  
  1106. //System.out.println( "xPlot:" + xPlot + "/yPlot:" + yPlot + "/iWidth:" + iWidth + "/iHigh:" + iHigh + "xBegin:" + xBegin + "/yBegin:" + yBegin + "/mx0:" + mx0 + "/mx1:" + mx1 + "/my0:" + my0 + "/my0:" + my1 );
  1107.         if(beforeFlag==0){
  1108.             mMinusFlag=minusFlag;
  1109.             mCorrect=correct;
  1110.             dxBegin = (mx0-xBegin)*xPlot/iWidth;
  1111.             dxEnd   = (mx1-xBegin)*xPlot/iWidth;
  1112.             dyBegin = (yBegin-my0)*yPlot/iHigh;
  1113.             dyEnd =   (yBegin-my1)*yPlot/iHigh;
  1114.             ixBegin=(int)dxBegin;
  1115.             ixEnd =(int)dxEnd;
  1116.             iyBegin=(int)dyBegin;
  1117.             iyEnd =(int)dyEnd;
  1118.  
  1119. //            if((ixEnd-ixBegin==0.0)||(Math.abs(dyEnd-dyBegin)<0.000001)) return;
  1120.             double xxx = Math.abs(dxEnd-dxBegin);
  1121.             double yyy = Math.abs(dyEnd-dyBegin);
  1122. //System.out.println( "xxx:" + xxx + "/yyy:" + yyy );
  1123.             if( xxx == 0.0 || yyy == 0.0 )
  1124.                 return;
  1125.  
  1126.             mxTimeBegin=(double)dxBegin;
  1127.             mxTimeEnd =(double) dxEnd;
  1128.  
  1129.             myValueBegin=dyBegin;
  1130.             myValueEnd=dyEnd;
  1131.             mxChange =iWidth/(mxTimeEnd-mxTimeBegin);
  1132.             if(mxChange<0) mxChange =-mxChange;
  1133.             myChange = iHigh/(myValueEnd-myValueBegin);
  1134.             if(myChange<0) myChange = -myChange;
  1135.             mxPlot=mxTimeEnd-mxTimeBegin;
  1136.             myPlot=myValueEnd-myValueBegin;
  1137.         }else if(beforeFlag == 1){
  1138.             dxBegin = (mx0-xBegin)*mxPlot/iWidth+mxTimeBegin;
  1139.             dxEnd   = (mx1-xBegin)*mxPlot/iWidth+mxTimeBegin;
  1140.             dyBegin = (yBegin-my0)*myPlot/iHigh+myValueBegin;
  1141.             dyEnd =   (yBegin-my1)*myPlot/iHigh+myValueBegin;
  1142.             ixBegin=(int)dxBegin;
  1143.             ixEnd =(int)dxEnd;
  1144.             iyBegin=(int)dyBegin;
  1145.             iyEnd =(int)dyEnd;
  1146.  
  1147. //System.out.println( "dxEnd:" + dxEnd + "/dxBegin:" + dxBegin + "/dyEnd:" + dyEnd + "/dyBegin:" + dyBegin );
  1148.  
  1149. window.messageWindow.setDebugMessage( "dxEnd:" + dxEnd + "/dxBegin:" + dxBegin + "/dyEnd:" + dyEnd + "dyBegin:" + dyBegin );
  1150.             if( ( Math.abs( dxEnd - dxBegin ) < 0.000001 ) ||
  1151.                 ( Math.abs( dyEnd - dyBegin ) < 0.000001 ) )
  1152.             {
  1153.                 return;
  1154.             }
  1155.  
  1156.             mxTimeBegin=(double)dxBegin;
  1157.             mxTimeEnd =(double) dxEnd;
  1158.  
  1159.             myValueBegin=dyBegin;
  1160.             myValueEnd=dyEnd;
  1161.             mxChange =iWidth/(mxTimeEnd-mxTimeBegin);
  1162.             if(mxChange<0) mxChange =-mxChange;
  1163.             myChange = iHigh/(myValueEnd-myValueBegin);
  1164.             if(myChange<0) myChange = -myChange;
  1165.             mxPlot=mxTimeEnd-mxTimeBegin;
  1166.             myPlot=myValueEnd-myValueBegin;
  1167.  
  1168.  
  1169.         }
  1170. window.messageWindow.setDebugMessage( "mxTimeBegin:" + mxTimeBegin + "/mxTimeEnd:" + mxTimeEnd + "/myValueBegin:" + myValueBegin + "/myValueEnd:" + myValueEnd + "/mxChange:" + mxChange + "/myChange:" + myChange + "/mxPlot:" + mxPlot + "/myPlot:" + myPlot );
  1171. //System.out.println( "mxTimeBegin:" + mxTimeBegin + "/mxTimeEnd:" + mxTimeEnd );
  1172. //System.out.println( "myValueBegin:" + myValueBegin + "/myValueEnd:" + myValueEnd );
  1173.     }
  1174.  
  1175.     /**
  1176.      * Calculate the coordinate
  1177.      * @return   double  X or Y-coordinate 
  1178.      * @param xxx    X or Y-maximum 
  1179.      */
  1180.     private synchronized double ceilToPow10(double xxx){
  1181.         if(xxx==0.0) {
  1182.             return 1.0;
  1183.         }
  1184.         double tmp =1.0;
  1185.         if(1.0<xxx){
  1186.             while(tmp<xxx){
  1187.                 tmp *= 10.0;
  1188.             }
  1189.         }else {
  1190.             while(xxx<=tmp){
  1191.                 tmp*=0.1;
  1192.             }
  1193.             tmp*=10.0;
  1194.         }
  1195.         if(tmp>1.0 && xxx<0.5*tmp) tmp =0.5*tmp;
  1196.         return tmp;
  1197.     }
  1198.  
  1199.     /**
  1200.      * Override to exit when the window is closed.
  1201.      * @return void
  1202.      * @param e      WindowEvent
  1203.      */
  1204. /*
  1205.     protected void processWindowEvent(WindowEvent e) {
  1206.         super.processWindowEvent(e);
  1207.         if (e.getID() == WindowEvent.WINDOW_CLOSING) {
  1208.             if( confirmExit() )
  1209.             {
  1210.                 exit_actionPerformed();
  1211.             }
  1212.         }
  1213.     }
  1214. */
  1215.  
  1216.     /**
  1217.      * Override to exit confirming when the window is closed.
  1218.      * @return boolean
  1219.      */
  1220.     protected boolean confirmExit()
  1221.     {
  1222.         Object confirmText ="Really want to close this Tracer?";
  1223.         String confirmTitle ="Tracer";
  1224.         int optionType = JOptionPane.YES_NO_OPTION;
  1225.         int messageType = JOptionPane.QUESTION_MESSAGE;
  1226.         int selectedValue =JOptionPane.showConfirmDialog(this.getContentPane(),confirmText,
  1227.                                                                         confirmTitle,optionType,messageType);
  1228.         return (selectedValue == 0)? true : false;
  1229.     }
  1230.  
  1231.     /*
  1232.      * Close the window.
  1233.      * @return void
  1234.      */
  1235.     public void exit_actionPerformed()
  1236.     {
  1237.         try
  1238.         {
  1239.             // 2002.3.5
  1240.             window.removeAccessListener( this );
  1241.             while( getRunningFlag() )
  1242.             {
  1243.                 Thread.sleep( 50 );
  1244.             }
  1245.             this.setVisible(false);
  1246.             // 2002.1.16
  1247.             this.dman.deleteTempFiles();
  1248. //System.out.println( "setTracerState@exit_actionPerformed(no." + tracerNumber + ")" );
  1249.             window.df.setTracerState(tracerNumber,-1); 
  1250.         }catch(Exception ex){
  1251.             window.messageWindow.setErrorMessage( ex );
  1252.         }
  1253.  
  1254.         this.dispose();
  1255.     }
  1256.  
  1257.     /**
  1258.      * Exiting process 
  1259.      * @return void
  1260.      */
  1261.     public void exitTracer()
  1262.     {
  1263.         exit_actionPerformed();
  1264.     }
  1265.  
  1266.  
  1267.     /**
  1268.      *Adapter
  1269.      */
  1270.     MouseAdapter myMouseAdapter = new MouseAdapter(){
  1271.         public void mousePressed(MouseEvent e) {
  1272.             if (e.getModifiers() == e.BUTTON3_MASK){
  1273.                 int i=0;
  1274.                 for(i=0;i<arraySize;i++){
  1275.                     if(e.getSource()==jCheckBox[i])
  1276.                         break;
  1277.                 }
  1278.  
  1279.  
  1280.                 if(wType[i]==1){
  1281.                     try{
  1282.                         window.df.setEntrySelected(-1,1,type[i]);
  1283.                     }catch (Exception ex){
  1284.                         window.messageWindow.setErrorMessage( ex );
  1285.                     }
  1286.                     Substance substance = new Substance(type[i],jCheckBox[i].getText(),
  1287.                         jCheckBox[i].getToolTipText(),window);
  1288.                     //window.vSubstance.addElement(substance);
  1289.                     substance.setVisible(true);
  1290.                     substance.setLocation(150+i*20,100+i*10);
  1291.                 }
  1292.  
  1293.                 if(wType[i]==2){
  1294.                     try{
  1295.                         window.df.setEntrySelected(-1,2,type[i]);
  1296.                     }catch(Exception ex){
  1297.                         window.messageWindow.setErrorMessage( ex );
  1298.                     }
  1299.                     Reactor reactor = new Reactor(type[i],jCheckBox[i].getText(),
  1300.                         jCheckBox[i].getToolTipText(),cName[i],window);
  1301.                     //window.vReactor.addElement(reactor);
  1302.                     reactor.setVisible(true);
  1303.                     reactor.setLocation(150+i*20,100+i*10);
  1304.                 }
  1305.             }
  1306.         }
  1307.     };
  1308.  
  1309. }
  1310.  
  1311. /**
  1312.  * Graphics panel class
  1313.  * @author XD.Zheng
  1314.  * @version 1.0
  1315.  * @since JDK1.2.2
  1316.  */
  1317.  
  1318. class GPanel extends JPanel{
  1319.  
  1320.     /**
  1321.      * Instance of parent Tracer
  1322.      */
  1323.     Tracer tracer;
  1324.  
  1325.     // 2000.06.28 akira shiozawa
  1326.     private final int maxdata = 4096;
  1327.     volatile double data[][] = new double[maxdata][7];
  1328.  
  1329.     // 20002.3.19 akira shiozawa
  1330.     private FontMetrics fontInfo = null;
  1331.     public final int xMarginL = 30;
  1332.     public final int xMarginR = 32;
  1333.     public final int yMarginT = 20;
  1334.     public final int yMarginB = 22;
  1335.  
  1336.     public boolean bPainting = false;
  1337.  
  1338.     /*
  1339.      * Constructor
  1340.      *param tracer      Parent Tracer
  1341.      */
  1342.     public GPanel(Tracer tracer){
  1343.         int rx0=0;
  1344.         int ry0=0;
  1345.         int rx1=0;
  1346.         int rx2=0;
  1347.  
  1348.         this.tracer = tracer;
  1349.     }
  1350.  
  1351.     /**
  1352.      * Component drawing 
  1353.      *@return void
  1354.      *@param g       Graphics Object
  1355.      */
  1356.      public void paintComponent(Graphics g) {
  1357.         super.paintComponent(g);
  1358.  
  1359.         // 2002.4 akira shiozawa
  1360.         this.bPainting = true;
  1361.  
  1362. tracer.window.messageWindow.setDebugMessage( "----- tracerNumber:" + tracer.tracerNumber + "-paintComponent@" + getClass()+getName() );
  1363.  
  1364.         int y1=0;
  1365.         int y0=0;
  1366.         int x0=0;
  1367.         int x1=0;
  1368.  
  1369.         if( fontInfo == null )
  1370.         {
  1371.             fontInfo = g.getFontMetrics();
  1372.         }
  1373.  
  1374. //System.out.println( "Dimension:" + this.getWidth() + "/" + this.getHeight() + "//" + fontInfo.getMaxAdvance() );
  1375.  
  1376. //System.out.println( "xEnd:" + tracer.xEnd + "/yBegin:" + tracer.yBegin );
  1377.  
  1378.         // 2002.1.23 for concentration
  1379.         int valueIndex = (tracer.nTracerFlag == 1)?  4 : 1;
  1380.  
  1381.         if(tracer.magFlag ==0){
  1382.             
  1383.             tracer.defineScale();
  1384.  
  1385.             if(tracer.minusFlag==0){
  1386.                 g.drawString(""+tracer.getDoubleValue(tracer.yPlot) ,
  1387.                                 tracer.xBegin, (tracer.yEnd - fontInfo.getDescent()) );
  1388.                 g.drawString("0", tracer.xBegin, (tracer.yBegin + fontInfo.getAscent()) );
  1389.             }else if(tracer.minusFlag==1){
  1390.                 g.drawString(""+tracer.getDoubleValue(tracer.correct) ,
  1391.                                 tracer.xBegin, (tracer.yEnd - fontInfo.getDescent()));
  1392.                 g.drawString("-"+tracer.getDoubleValue(tracer.correct),
  1393.                                 tracer.xBegin,(tracer.yBegin + fontInfo.getAscent()));
  1394.             }else {
  1395.                 g.drawString("0", tracer.xBegin, (tracer.yEnd - fontInfo.getDescent()));
  1396.                 g.drawString("-"+ tracer.getDoubleValue(tracer.correct),
  1397.                                 tracer.xBegin,(tracer.yBegin + fontInfo.getAscent()));
  1398.             }
  1399.             String str = tracer.getDoubleValue( tracer.xPlot );
  1400.             g.drawString( str, (tracer.xEnd - fontInfo.stringWidth( str ) / 2),
  1401.                                                 (tracer.yBegin + fontInfo.getAscent()));
  1402.  
  1403.             g.setColor(Color.lightGray);
  1404.             g.drawRect( tracer.xBegin, tracer.yEnd,
  1405.                 (tracer.xEnd - tracer.xBegin), (tracer.yBegin - tracer.yEnd) );
  1406.  
  1407.  
  1408.             g.setColor(getForeground());
  1409.  
  1410.             for(int j=0;j<8;j++){
  1411.                 if(tracer.jCheckBox[j].isSelected()){
  1412.                     g.setColor(tracer.gColor[j]);
  1413.  
  1414.  
  1415. // ---> 2001.6.28 akira shiozawa
  1416.                     int index = 0;
  1417.                     int max = -1;
  1418.  
  1419.                     do
  1420.                     {
  1421.                         max = tracer.dman.getTracerDataBlock(
  1422.                                     (tracer.tracerNumber + "-" + j + "-" + tracer.type[j]),
  1423.                                                 data, index, maxdata );
  1424. //System.out.println( "tracer.type:" + tracer.type[j] + "/max:" + max );
  1425.                         if( max <= 0 )
  1426.                         {
  1427.                             break;
  1428.                         }
  1429.                         
  1430.                         for( int i = 1; i < max; i++, index++ )
  1431.                         {
  1432.                             double dx1= data[i][0];
  1433.                             double dx0= data[i-1][0];
  1434.                             
  1435.                             double dy1= data[i][valueIndex] + tracer.correct;
  1436.                             double dy0= data[i-1][valueIndex] + tracer.correct;
  1437.                             
  1438.                             x1= (int) (dx1*tracer.xChange);
  1439.                             x0= (int)(dx0*tracer.xChange);
  1440.  
  1441.                             y1=(int)(dy1*tracer.yChange);
  1442.                             y0=(int)(dy0*tracer.yChange);
  1443.                             g.drawLine(x0+ tracer.xBegin ,tracer.yBegin-y0,
  1444.                                 x1+ tracer.xBegin,tracer.yBegin-y1);
  1445.                         }
  1446.                     }while( max > 0 );
  1447.  
  1448. // <--- akira shiozawa
  1449.                 }
  1450.             }
  1451.         }else{
  1452.             g.setColor(Color.lightGray);
  1453.             g.drawRect( tracer.xBegin, tracer.yEnd,
  1454.                 (tracer.xEnd - tracer.xBegin), (tracer.yBegin - tracer.yEnd) );
  1455.  
  1456.             for(int j=0;j<8;j++){
  1457.  
  1458.                 if(tracer.jCheckBox[j].isSelected()){
  1459.                     g.setColor(tracer.gColor[j]);
  1460.  
  1461. // ---> 2001.6.28 akira shiozawa
  1462.                     int index = 0;
  1463.                     int max = -1;
  1464.  
  1465.                     do
  1466.                     {
  1467.                         max = tracer.dman.getTracerDataBlock( 
  1468.                                     (tracer.tracerNumber + "-" + j + "-" + tracer.type[j]),
  1469.                                                 data, index, maxdata );
  1470.  
  1471.                         if( max <= 0 )
  1472.                         {
  1473.                             break;
  1474.                         }
  1475.                         
  1476.                         for( int i = 1; i < max; i++, index++ )
  1477.                         {
  1478.                             double dx0= data[i-1][0];
  1479.                             double dx1= data[i][0];
  1480.                             double dy0= data[i-1][valueIndex] + tracer.correct;
  1481.                             double dy1= data[i][valueIndex] + tracer.correct;
  1482.                             
  1483.                             // 2002.4 akira shiozawa
  1484.                             Point2D.Double p0 = new Point2D.Double( dx0, dy0 );
  1485.                             Point2D.Double p1 = new Point2D.Double( dx1, dy1 );
  1486.                             if( getDrawPoints( p0, p1 ) )
  1487.                             {
  1488.                                 y1= (int)((p1.getY()-tracer.myValueBegin)*tracer.myChange);
  1489.                                 x1= (int)((p1.getX()-tracer.mxTimeBegin)*tracer.mxChange);
  1490.                                 x0= (int)((p0.getX()-tracer.mxTimeBegin)*tracer.mxChange);
  1491.                                 y0 =(int)((p0.getY()-tracer.myValueBegin)*tracer.myChange);
  1492. /**/
  1493. tracer.window.messageWindow.setDebugMessage( "xy0(" + x0 + "," + y0 + ") - xy1(" + x1 + "," + y1 + ")" );
  1494. tracer.window.messageWindow.setDebugMessage( "pxy0(" + p0.getX() + "," + p0.getY() + ") - pxy1(" + p1.getX() + "," + p1.getY() + ")" );
  1495. tracer.window.messageWindow.setDebugMessage( "dxy0(" + dx0 + "," + dy0 + ") - dxy1(" + dx1 + "," + dy1 + ")" );
  1496.                                   g.drawLine(x0+ tracer.xBegin ,tracer.yBegin-y0,
  1497.                                                   x1+ tracer.xBegin,tracer.yBegin-y1);
  1498.                             }
  1499.                         }
  1500.                     }while( max > 0 );
  1501.  
  1502. // <--- akira shiozawa
  1503.  
  1504.                 }
  1505.             }
  1506.  
  1507.             g.setColor(getForeground());
  1508.             double end= tracer.myValueEnd-tracer.mCorrect;
  1509.             double  begin= tracer.myValueBegin-tracer.mCorrect;
  1510.             g.drawString(""+tracer.getDoubleValue(end) , 20, tracer.yEnd - fontInfo.getDescent());
  1511.             g.drawString(""+tracer.getDoubleValue(begin),20,tracer.yBegin - fontInfo.getDescent());
  1512.             g.drawString(""+tracer.getDoubleValue(tracer.mxTimeBegin), tracer.xBegin,tracer.yBegin+fontInfo.getAscent());
  1513.             String str = (String)tracer.getDoubleValue(tracer.mxTimeEnd);
  1514.             g.drawString(""+tracer.getDoubleValue(tracer.mxTimeEnd) ,
  1515.                 (tracer.xEnd - fontInfo.stringWidth( str ) / 2), tracer.yBegin+fontInfo.getAscent());
  1516.  
  1517.         }
  1518.  
  1519.         if(tracer.rflag){
  1520.             g.setColor(Color.lightGray);
  1521.             int p1=0;
  1522.             int p2=0;
  1523.             int width=0;
  1524.             int height=0;
  1525.             if(tracer.rx1>tracer.rx0){
  1526.                 p1=tracer.rx0;
  1527.                 width=tracer.rx1-tracer.rx0;
  1528.             }else{
  1529.                 p1=tracer.rx1;
  1530.                 width=tracer.rx0-tracer.rx1;
  1531.             }
  1532.             if(tracer.ry1>tracer.ry0){
  1533.                 p2=tracer.ry0;
  1534.                 height=tracer.ry1-tracer.ry0;
  1535.             }else{
  1536.                 p2=tracer.ry1;
  1537.                 height=tracer.ry0-tracer.ry1;
  1538.             }
  1539.             g.drawRect(p1,p2,width,height);
  1540.         }
  1541.  
  1542.         // cross cursor
  1543.         if( Tracer.mousex > 0 || Tracer.mousey > 0 )
  1544.         {
  1545.             int dx = ((tracer.magFlag == 0)?  (int)(Tracer.mousex * tracer.xChange) :
  1546.                             (int)((Tracer.mousex - tracer.mxTimeBegin) * tracer.mxChange));
  1547.             int dy = ((tracer.magFlag == 0)?
  1548.                 (int)((Tracer.mousey + tracer.correct) * tracer.yChange) :
  1549.                 (int)((Tracer.mousey + tracer.mCorrect - tracer.myValueBegin) * tracer.myChange));
  1550.             dx += tracer.xBegin;
  1551.             dy = tracer.yBegin - dy;
  1552. //System.out.println( "dx:" + dx + "/dy:" + dy + "/correct:" + tracer.correct + "/yPlot:" + tracer.yPlot + "/mousey:" + Tracer.mousey + "/mousex:" + Tracer.mousex + "/yEnd:" + tracer.yEnd + "/yBegin:" + tracer.yBegin );
  1553.  
  1554.             if( dx < tracer.xEnd && dy < tracer.yBegin && dx > tracer.xBegin && dy >= tracer.yEnd )
  1555.             {
  1556.                 tracer.label1.setText(""+ tracer.getDoubleValue(tracer.mousex) +":" +
  1557.                                                     tracer.getDoubleValue(tracer.mousey));
  1558.                 if( dy > tracer.yEnd )
  1559.                 {
  1560.                     g.setColor(Color.lightGray);
  1561.                     g.drawLine(tracer.xBegin,dy,tracer.xEnd,dy);
  1562.                     g.drawLine(dx,tracer.yEnd,dx,tracer.yBegin);
  1563.                 }
  1564.             }
  1565.             else
  1566.             {
  1567.                 tracer.label1.setText("    :    ");
  1568.             }
  1569.  
  1570.         }
  1571.         
  1572.         // 2002.4 akira shiozawa
  1573.         this.bPainting = false;
  1574.         
  1575.     }
  1576.     
  1577.     
  1578.     private boolean getDrawPoints( Point2D.Double p0, Point2D.Double p1 )
  1579.     {
  1580.         Point2D.Double pt0 = (Point2D.Double)p0.clone();
  1581.         Point2D.Double pt1 = (Point2D.Double)p1.clone();
  1582.         
  1583.         boolean ret = true;
  1584.         double x,y;
  1585.         
  1586.         if( tracer.magFlag == 0 )
  1587.         {
  1588.             return true;
  1589.         }
  1590.         else if( pt0.getX() > tracer.mxTimeEnd || pt1.getX() < tracer.mxTimeBegin ||
  1591.             ( pt0.getY() < tracer.myValueBegin && pt1.getY() < tracer.myValueBegin ) ||
  1592.             ( pt0.getY() > tracer.myValueEnd && pt1.getY() > tracer.myValueEnd ) )
  1593.         {
  1594.             return false;
  1595.         }
  1596.         
  1597.         if( pt0.getX() < tracer.mxTimeBegin ||
  1598.             pt0.getY() < tracer.myValueBegin || pt0.getY() > tracer.myValueEnd )
  1599.         {
  1600.             if( pt0.getX() < tracer.mxTimeBegin )
  1601.             {
  1602.                 y = ( (pt1.getX() - tracer.mxTimeBegin) * Math.abs( pt1.getY() - pt0.getY() ))
  1603.                         / (pt1.getX() - pt0.getX());
  1604.                 y = (pt1.getY() >= pt0.getY())? (pt1.getY() - y) : (pt1.getY() + y);
  1605.             }
  1606.             else
  1607.             {
  1608.                 y = pt0.getY();
  1609.             }
  1610.             
  1611.             if( y <= tracer.myValueBegin )
  1612.             {
  1613.                 x = ((pt1.getX() - pt0.getX()) * Math.abs( tracer.myValueBegin - pt0.getY() )) / 
  1614.                         Math.abs( pt1.getY() - pt0.getY() );
  1615.                 x = pt0.getX() + x;
  1616.                 p0.setLocation( x, tracer.myValueBegin );
  1617.             }
  1618.             else if( y >= tracer.myValueEnd )
  1619.             {
  1620.                 x = ((pt1.getX() - pt0.getX()) * Math.abs( pt0.getY() - tracer.myValueEnd )) / 
  1621.                         Math.abs( pt1.getY() - pt0.getY() );
  1622.                 x = pt0.getX() + x;
  1623.                 p0.setLocation( x, tracer.myValueEnd );
  1624.             }
  1625.             else
  1626.             {
  1627.                 p0.setLocation( tracer.mxTimeBegin, y );
  1628.             }
  1629.             if( p0.getX() > tracer.mxTimeEnd )
  1630.             {
  1631.                 ret = false;
  1632.             }
  1633.         }
  1634.         
  1635.         if( p1.getX() > tracer.mxTimeEnd ||
  1636.             p1.getY() > tracer.myValueEnd || p1.getY() < tracer.myValueBegin )
  1637.         {
  1638.             if( pt1.getX() > tracer.mxTimeEnd )
  1639.             {
  1640.                 y = (Math.abs( pt1.getY() - pt0.getY() ) * (tracer.mxTimeEnd - pt0.getX())) / 
  1641.                         (pt1.getX() - pt0.getX());
  1642.                 y = (pt1.getY() >= pt0.getY())?  (pt0.getY() + y ) : (pt0.getY() - y);
  1643.             }
  1644.             else
  1645.             {
  1646.                 y = pt1.getY();
  1647.             }
  1648.             
  1649.             if( y <= tracer.myValueBegin )
  1650.             {
  1651.                 x = (Math.abs( tracer.myValueBegin - pt1.getY() ) * (pt1.getX() - pt0.getX())) /
  1652.                         Math.abs( pt1.getY() - pt0.getY() );
  1653.                 x = pt1.getX() - x;
  1654.                 p1.setLocation( x, tracer.myValueBegin );
  1655.             }
  1656.             else if( y >= tracer.myValueEnd )
  1657.             {
  1658.                 x = (Math.abs( pt1.getY() - tracer.myValueEnd ) * (pt1.getX() - pt0.getX())) /
  1659.                         Math.abs( pt1.getY() - pt0.getY() );
  1660.                 x = pt1.getX() - x;
  1661.                 p1.setLocation( x, tracer.myValueEnd );
  1662.             }
  1663.             else
  1664.             {
  1665.                 p1.setLocation( tracer.mxTimeEnd, y );
  1666.             }
  1667.             if( p1.getX() < tracer.mxTimeBegin )
  1668.             {
  1669.                 ret = false;
  1670.             }
  1671.         }
  1672.         
  1673.         if( ret )
  1674.         {
  1675.             tracer.window.messageWindow.setDebugMessage( "_pxy0(" + p0.getX() + "," + p0.getY() +
  1676.                                                 ") - _pxy1(" + p1.getX() + "," + p1.getY() + ")" );
  1677.         }
  1678.         return ret;
  1679.     }
  1680. }
  1681.